﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz;
using Quartz.Impl;
using Topshelf;
using Quartz.Impl.Calendar;

namespace FJHost
{
    class ServicesSchedule : ServiceControl
    {
        ISchedulerFactory factory;
        IScheduler scheduler;
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        public bool Start(HostControl hostControl)
        {
            factory = new StdSchedulerFactory();
            scheduler = factory.GetScheduler();

            var dailyCalendar = new DailyCalendar("00:01", "23:59");
            dailyCalendar.InvertTimeRange = true;
            scheduler.AddCalendar("cal1", dailyCalendar, false, false);

            scheduler.Start();
            log.Info("Finished Start!!");
            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            scheduler.Clear();
            log.Info("Finished Stop!!");
            return true;
        }
    }
}
